<?php
namespace app\home\controller;

use app\common\controller\Frontend;
use think\Controller;
use think\Request;
use think\Session;
use think\Db;
use think\Cache;
use think\Config;
//use think\Db;

/**
 * 前端基础控制器
 *
 * @icon fa fa-circle-o
 */
class Base extends Frontend
{
    protected $model = null;

    public function _initialize()
    {
		$request = Request::instance();
		if(Cache::get('cache') == false){
			$category = Db::name('category')->select();
			$cache['category'] = $category;
			$cache['site'] = config('site');
			Cache::set('cache',$cache);
		}
		
		$this->cache = Cache::get('cache');
		$this->module = $request->module();
		$this->assign('module',$this->module);
		$this->assign('cache',Cache::get('cache'));
		$this->assign('color1','#5EB04A');
		$this->assign('color2','#FF9900');
		$site = Config::get("site");
		
		$ua = input('?ua') ? input('ua') : 0;
		if($ua === 'pc'){
            if(Session::get('ua') != 'pc'){
				Session::set('ua','pc');
			}
		}
        $url = $request->url();
		if($url =='/'){$wap_url = $url.'m';}else{$wap_url = str_replace('/'.$request->module(),"/m",$url);}
		if($request->isMobile() && Session::get('ua') != 'pc' && $request->controller() != 'Review'){
			$url = $request->domain().$wap_url;
			ob_end_clean();
			header('Location:'.$url);
		}
		parent::_initialize();
		
    }
	
	/*
	public function _initialize()
    {
		if(Cache::get('cache') == false){
		    $one = Db::name('configvalue')->where('id','config')->find();
			$category = Db::name('category')->select();
			$cache['config'] = json_decode($one['content'],true);
			$cache['category'] = $category;
			Cache::set('cache.config',$cache['config']);
			Cache::set('cache.category',$cache['category']);
		}
		
		$this->assign('cache',Cache::get('cache'));
		$this->assign('color1','#5EB04A');
		$this->assign('color2','#FF9900');
        parent::_initialize();
    }
	
	*/
	
}
